import 'package:farmer_app/widgets/pages/login/check_code.dart';
import 'package:farmer_app/widgets/pages/login/count_time_button.dart';
import 'package:flutter/material.dart';
import 'package:pin_code_fields/pin_code_fields.dart';

class LoginCodePage extends StatelessWidget {
  LoginCodePage({
    Key? key,
    required this.phoneNumber, // 接收一个phoneNumber参数
  }) : super(key: key);
  final String phoneNumber;
  TextEditingController textCodeController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('输入验证码'),
      ),
      body: SingleChildScrollView(
          child: Column(children: [
        Padding(
            padding: const EdgeInsets.only(top: 50),
            child: Center(
              child: Text('填写验证码',
                  style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)),
            )),
        Padding(
            padding: const EdgeInsets.only(bottom: 30, top: 20),
            child: Center(
              child: Text('验证码已发送至 +86-' + this.phoneNumber),
            )),
        Padding(
            padding:
                const EdgeInsets.only(left: 30, bottom: 50, top: 20, right: 30),
            child: CheckCodeComponent(
                textCodeController: this.textCodeController)),
        Padding(
          padding: EdgeInsets.only(left: 0, top: 80, bottom: 50),
          child: CountTimeButton(
              text: '重新获取验证码',
              countdownTime: 60,
              onPressed: () {
                this.textCodeController.clear();
                print('重新获取phone code');
                // if(validPhone(phone)){
                //
                // } else {
                //   // todo 加错误提示
                // }
              }
          ),
        ),
      ])),
    );
  }
}

// class LoginCodePage extends StatefulWidget {
//   const LoginCodePage({
//     Key? key,
//     required this.phoneNumber,  // 接收一个phoneNumber参数
//   }) : super(key: key);
//   final String phoneNumber;
//
//   @override
//   State<LoginCodePage> createState() => _LoginCodeState(phoneNumber: this.phoneNumber);
// }
//
// class _LoginCodeState extends State<LoginCodePage> {
//
//   _LoginCodeState({
//     required this.phoneNumber,
//   });
//
//   TextEditingController textCodeController = TextEditingController();
//   String currentText = "";
//   String phoneNumber = "";
//
//   @override
//   Widget build(BuildContext context) {
//
//   }
// }
